import { getUserByPositionApi } from "@/api/common";
import { reactive, ref } from "vue";

export default function InitHook() {
  const formState = reactive<Partial<WarehouseManagement.AddForm>>({
    cnName: undefined,
    address: undefined,
    warehouseManagerId: undefined,
    managerPhone: undefined,
    cityModel: [],
    stateName: undefined,
    cityName: undefined,
    zoneName: undefined,
    status: 1
  });
  const loading = ref<boolean>(false);
  const formDataRef = ref<any>(null);
  const userOpts = ref<Array<Base.GeneraDataType>>([]);
  const filter = (inputValue: string, path: Array<Base.GeneraDataType>) => {
    return path.some(option => option.name.toLowerCase().indexOf(inputValue.toLowerCase()) > -1);
  };
  const getUserOpts = () => {
    return getUserByPositionApi({ position: 8, status: 1 }).then((res: any) => {
      const { code, data } = res;
      if (code === 200) {
        userOpts.value = data || [];
      }
    });
  };
  return {
    formState,
    formDataRef,
    loading,
    filter,
    userOpts,
    getUserOpts
  };
}
